﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using TestPlatform.Core;
using Aquiles.Helpers.Encoders;
using Apache.Cassandra;
using Aquiles.Helpers;
using Aquiles.Cassandra10;
using Aquiles.Core.Cluster;

namespace TestPlatform.Performer.Cassandra
{
    public class CassandraUpdatePerformer : BaseUpdatePerformer
    {
        public override string UnderlyinEngine { get { return "Cassandra"; } }

        public CassandraUpdatePerformer()
            : base(new CassandraHelper())
        {

        }

        protected override void UpdateEntity(Guid id)
        {
            byte[] key = ByteEncoderHelper.GuidEncoder.ToByteArray(id);
            ColumnParent columnParent = new ColumnParent();            

            Column nameColumn = new Column()
            {
                Name = ByteEncoderHelper.UTF8Encoder.ToByteArray("name"),
                Value = ByteEncoderHelper.UTF8Encoder.ToByteArray("ala ma kota"),
                Timestamp = UnixHelper.UnixTimestamp,

            };

            columnParent.Column_family = CassandraHelper.UserCF;

            ICluster cluster = AquilesHelper.RetrieveCluster("MGR-Cluster");
            cluster.Execute(new ExecutionBlock(c =>
            {               
                c.insert(key, columnParent, nameColumn, ConsistencyLevel.ONE);                

                return null;
            }), "MGR");
        }
    }
}
